<?php
/**
 * @author Demianchuk Dmitro
 * @email d.demianchuk@gmail.com
 * @date 06.01.12
 * @version 1.0
 * @package application
 */
class LoginController extends AController
{
	private $_loginUrl = '/adminArea/';
	public $defaultAction = 'index';
	public $layout = '//layouts/auth';

	public function actionIndex(){
		if(!Yii::app()->user->isGuest){
			Yii::app()->request->redirect($this->_loginUrl);
		}
		if(isset($_POST['email']) && isset($_POST['password'])){
			$identity = new UserIdentity($_POST['email'],$_POST['password']);
			if($identity->authenticate())
			{
				Yii::app()->user->login($identity);
				Yii::app()->request->redirect($this->_loginUrl);
			}
			else
			{
				echo $identity->errorMessage;
			}
		}
		$this->render('loginPage');
	}

	public function actionLogout(){
		Yii::app()->user->logout();
		Yii::app()->request->redirect('/adminArea/login');
	}

	public function actionAccessDenied(){
		$this->render('accessDenied');
	}
}
